package com.yun.datastructure.linear.list.linkedlist.leetcode;

import com.yun.datastructure.linear.list.linkedlist.ListNode;

public class Leetcode876 {

    public ListNode middleNode(ListNode head) {
        ListNode p1=head;
        ListNode p2=head;
        while (p2!=null&&p2.next!=null){
            p1=p1.next;
            p2=p2.next;
            p2=p2.next;
        }
        return p1;
    }

    public static void main(String[] args) {
        ListNode head = ListNode.of(1, 2, 3, 4, 5, 6);
        ListNode n1 = new Leetcode876().middleNode(head);
        System.out.println(n1);
    }
}
